package com.atguigu.gmall.product.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http;
import com.atguigu.gmall.common.cache.GmallCache;
import com.atguigu.gmall.common.constant.MqConst;
import com.atguigu.gmall.common.constant.RedisConst;
import com.atguigu.gmall.common.service.RabbitService;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.mapper.*;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.amqp.RabbitTemplateConfigurer;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;


import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

@Service
public class ManageServiceImpl implements ManageService {
    @Autowired
    private BaseCategory1Mapper baseCategory1Mapper;
    @Autowired
    private BaseCategory2Mapper baseCategory2Mapper;
    @Autowired
    private BaseCategory3Mapper baseCategory3Mapper;
    @Autowired
    private BaseAttrInfoMapper baseAttrInfoMapper;
    @Autowired
    private BaseAttrValueMapper baseAttrValueMapper;
    //大保存 权限5张表
    @Autowired
    private SpuInfoMapper spuInfoMapper;
    @Autowired
    private BaseSaleAttrMapper baseSaleAttrMapper;
    @Autowired
    private SpuPosterMapper spuPosterMapper;
    @Autowired
    private SpuSaleAttrMapper spuSaleAttrMapper;
    @Autowired
    private SpuImageMapper spuImageMapper;
    @Autowired
    private SpuSaleAttrValueMapper spuSaleAttrValueMapper;
    @Autowired
    private SkuAttrValueMapper skuAttrValueMapper;
    @Autowired
    private SkuImageMapper skuImageMapper;
    @Autowired
    private SkuInfoMapper skuInfoMapper;
    @Autowired
    private SkuSaleAttrValueMapper skuSaleAttrValueMapper;
    @Autowired
    private BaseCategoryViewMapper baseCategoryViewMapper;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private RedissonClient redissonClient;
    @Autowired
    private BaseTrademarkMapper baseTrademarkMapper;

    @Autowired
    private RabbitService rabbitService;

    /* sku_attr_value
       sku_image
       sku_info
       sku_sale_attr_value*/
    @Override
    public List<BaseCategory1> getCategory1() {
        //查询商品的属性列表
        return baseCategory1Mapper.selectList(null);
    }

    @Override
    public List<BaseCategory2> getCategory2(Long category1Id) {
        // select * from baseCategory2 where Category1Id = ?
        return baseCategory2Mapper.selectList(new QueryWrapper<BaseCategory2>().eq("category1_id", category1Id));
    }

    @Override
    public List<BaseCategory3> getCategory3(Long category2Id) {
        // select * from baseCategory3 where Category2Id = ?
        return baseCategory3Mapper.selectList(new QueryWrapper<BaseCategory3>().eq("category2_id", category2Id));
    }

    @Override
    public List<BaseAttrInfo> getAttrInfoList(Long category1Id, Long category2Id, Long category3Id) {
        return baseAttrInfoMapper.selectBaseAttrInfoList(category1Id, category2Id, category3Id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)//添加事务回滚:底层是spring的AOP的动态代理
    //调用service的save方法 要先判断该属性得到ID是否已经存在
    public void saveAttrInfo(BaseAttrInfo baseAttrInfo) {
        //ID存在就更新不存在就新增
        if (baseAttrInfo.getId() != null) {
            baseAttrInfoMapper.updateById(baseAttrInfo);
        } else {
            baseAttrInfoMapper.insert(baseAttrInfo);
        }
        // baseAttrValue 平台属性值
        //修改：通过先删除[baseAttrValue]再新增的方式
        QueryWrapper<BaseAttrValue> baseAttrValueQueryWrapper = new QueryWrapper<>();
        baseAttrValueQueryWrapper.eq("attr_id", baseAttrInfo.getId());
        baseAttrValueMapper.delete(baseAttrValueQueryWrapper);

        //获取页面传递过来的所有平台属性值的数据
        List<BaseAttrValue> attrValueList = baseAttrInfo.getAttrValueList();
        if (attrValueList != null && attrValueList.size() > 0) {
            //循环遍历
            for (BaseAttrValue baseAttrValue : attrValueList) {
                //获取平台属性ID给attrId
                baseAttrValue.setAttrId(baseAttrInfo.getId());
                baseAttrValueMapper.insert(baseAttrValue);
            }
        }
    }

    @Override
    public BaseAttrInfo getAttrInfo(Long attrId) {
        BaseAttrInfo baseAttrInfo = baseAttrInfoMapper.selectById(attrId);
        // 查询到最新的平台属性值集合数据放入平台属性中！
        baseAttrInfo.setAttrValueList(getAttrValueList(attrId));
        return baseAttrInfo;
    }

    //    根据属性id获取属性值
    private List<BaseAttrValue> getAttrValueList(Long attrId) {
        // select * from baseAttrValue where attrId = ?
        QueryWrapper<BaseAttrValue> querywrapper = new QueryWrapper<>();
        querywrapper.eq("attr_id", attrId);
        List<BaseAttrValue> baseAttrValueList = baseAttrValueMapper.selectList(querywrapper);
        return baseAttrValueList;
    }

    @Override
    public IPage<SpuInfo> getSpuInfoPage(Page<SpuInfo> spuInfoPage, SpuInfo spuInfo) {

        //select * from spu_info where category3_id = ? order by id desc limit 0,10;
        QueryWrapper<SpuInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("category3_id", spuInfo.getCategory3Id());
        queryWrapper.orderByDesc("id");
        return spuInfoMapper.selectPage(spuInfoPage, queryWrapper);
    }

    @Override
    public List<BaseSaleAttr> getBaseSaleAttrList() {
        List<BaseSaleAttr> baseSaleAttrList = baseSaleAttrMapper.selectList(null);
        return baseSaleAttrList;
    }

    //大保存商品属性
    /* spu_image 图片
       spu_info  属性
       spu_poster 海报
       spu_sale_attr 销售属性
       spu_sale_attr_value  销售值
    */
    @Override
    @Transactional(rollbackFor = Exception.class) //设计多表查询加事务
    public void saveAttrInfo(SpuInfo spuInfo) {

        //1、插入spu_info
        spuInfoMapper.insert(spuInfo);
        //2、插入spu_image
        List<SpuImage> spuImageList = spuInfo.getSpuImageList();
        if (!CollectionUtils.isEmpty(spuImageList)) {
            spuImageList.forEach(spuImage -> {
                spuImage.setSpuId(spuInfo.getId()); //因为insert在上面所以ID不会为空底层主键自增
                spuImageMapper.insert(spuImage);
            });

        }
//       3、插入spu_poster
        List<SpuPoster> spuPosterList = spuInfo.getSpuPosterList();
        if (!CollectionUtils.isEmpty(spuPosterList)) {
            spuPosterList.forEach(spuPoster -> {
                spuPoster.setSpuId(spuInfo.getId());
                spuPosterMapper.insert(spuPoster);
            });
        }

        //4、插入spu_sale_attr
        List<SpuSaleAttr> spuSaleAttrList = spuInfo.getSpuSaleAttrList();
        if (!CollectionUtils.isEmpty(spuSaleAttrList)) {
            spuSaleAttrList.forEach(spuSaleAttr -> {
                spuSaleAttr.setSpuId(spuInfo.getId());
                spuSaleAttrMapper.insert(spuSaleAttr);
                //5、插入spu_sale_attr_value
                List<SpuSaleAttrValue> spuSaleAttrValueList = spuSaleAttr.getSpuSaleAttrValueList();
                if (!CollectionUtils.isEmpty(spuSaleAttrValueList)) {
                    spuSaleAttrValueList.forEach(spuSaleAttrValue -> {
                        spuSaleAttrValue.setSpuId(spuInfo.getId());
                        spuSaleAttrValue.setSaleAttrName(spuSaleAttr.getSaleAttrName());
                        spuSaleAttrValueMapper.insert(spuSaleAttrValue);
                    });
                }
            });
        }
    }

    //Sku获取图片加载
    @Override
    public List<SpuImage> getSpuImageList(Long spuId) {
        QueryWrapper<SpuImage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("spu_id", spuId);
        return spuImageMapper.selectList(queryWrapper);
    }

    //Sku获取销售属性
    @Override
    public List<SpuSaleAttr> getSpuSaleAttrList(Long spuId) {
        return spuSaleAttrMapper.selectSpuSaleAttrList(spuId);
    }

    /*
    * 创建关联4张表
    sku_attr_value
    sku_image
    sku_info
    sku_sale_attr_value
    * */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveSkuInfo(SkuInfo skuInfo) {
        //1、插入 sku_info
        skuInfoMapper.insert(skuInfo);
        //2、插入 sku_image
        List<SkuImage> skuImageList = skuInfo.getSkuImageList();
        if (!CollectionUtils.isEmpty(skuImageList)) {
            skuImageList.forEach(skuImage -> {
                skuImage.setSkuId(skuInfo.getId());
                skuImageMapper.insert(skuImage);
            });
        }
        //3、插入 sku_attr_value
        List<SkuAttrValue> skuAttrValueList = skuInfo.getSkuAttrValueList();

        if (!CollectionUtils.isEmpty(skuAttrValueList)) {
            skuAttrValueList.forEach(skuAttrValue -> {
                skuAttrValue.setSkuId(skuInfo.getId());
                skuAttrValueMapper.insert(skuAttrValue);
            });
        }
        //4、插入 sku_sale_attr_value
        List<SkuSaleAttrValue> skuSaleAttrValueList = skuInfo.getSkuSaleAttrValueList();
        skuSaleAttrValueList.forEach(skuSaleAttrValue -> {
            skuSaleAttrValue.setSkuId(skuInfo.getId());
            skuSaleAttrValue.setSkuId(skuInfo.getSpuId());
            skuSaleAttrValueMapper.insert(skuSaleAttrValue);
        });
    }

    //通过分页查询数据
    @Override
    public IPage<SkuInfo> getPage(Page<SkuInfo> pageParam) {
        QueryWrapper<SkuInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        IPage<SkuInfo> page = skuInfoMapper.selectPage(pageParam, queryWrapper);
        return page;
    }

    //上架  更改销售的状态 isSale = 1 表示已经上架
    @Override
    @Transactional
    public void onSale(Long skuId) {
        SkuInfo skuInfoUp = new SkuInfo();
        skuInfoUp.setId(skuId);
        skuInfoUp.setIsSale(1);
        skuInfoMapper.updateById(skuInfoUp);

        //发送一个消息队列
        //发送消息的内容，根据消费者的需求决定！
        rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_GOODS, MqConst.ROUTING_GOODS_UPPER, skuId);

    }


    //下架  更改销售的状态 isSale = 0 表示已经上架
    @Override
    @Transactional
    public void cancelSale(Long skuId) {
        SkuInfo skuInfoDown = new SkuInfo();
        skuInfoDown.setId(skuId);
        skuInfoDown.setIsSale(0);
        skuInfoMapper.updateById(skuInfoDown);
        //发送一个消息队列
        //发送消息的内容，根据消费者的需求决定！
        rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_GOODS, MqConst.ROUTING_GOODS_LOWER, skuId);

    }

    @Override
    public SkuInfo getSkuInfo(Long skuId) {//获取数据如果redis缓存中有直接获取   没有访问数据库DB获取
        //  获取skuInfo 数据！
        //  skuKey = sku:skuId:info;
        //  return getSkuInfoByRedis(skuId);    //redis方式上锁
        return getSkuInfoByRedisson(skuId);     //redission方式上锁
    }

    //两种方式上锁    redssion分布式锁
    private SkuInfo getSkuInfoByRedisson(Long skuId) {
        String skuKey = RedisConst.SKUKEY_PREFIX + skuId + RedisConst.SKUKEY_SUFFIX;
        try {
            //  skuInfo
            SkuInfo skuInfo = (SkuInfo) this.redisTemplate.opsForValue().get(skuKey);
            if (skuInfo == null) {
                //  缓存中没有数据
                //  上锁！redis  ，redisson！
                //  set key value ex/px timeout nx/xx;
                //  lockKey= sku:skuId:lock
                String lockKey = RedisConst.SKUKEY_PREFIX + skuId + RedisConst.SKULOCK_SUFFIX;
                RLock lock = redissonClient.getLock(lockKey);
                //  获取分布式锁！  1.尝试获取锁的时间 2.锁的过期时间 (>业务执行时间)3.时间单位
                // 看门狗机制 不设置过期时间 默认30s  1/3 秒自动续期
                boolean result = lock.tryLock(RedisConst.SKULOCK_EXPIRE_PX1, RedisConst.SKULOCK_EXPIRE_PX2, TimeUnit.SECONDS);
                //  result=true 表示 获取到锁！
                //  从最终结果来将需要重试么？ 不做重试可以么？
                if (result) {
                    try {
                        //  业务逻辑！
                        skuInfo = getSkuInfoDB(skuId);
                        //  防止一下缓存穿透！
                        if (skuInfo == null) {
                            SkuInfo skuInfo1 = new SkuInfo();
                            //  这个过期时间不应该太长
                            this.redisTemplate.opsForValue().set(skuKey, skuInfo1, RedisConst.SKUKEY_TEMPORARY_TIMEOUT, TimeUnit.SECONDS);
                            return skuInfo1;
                        }
                        //  放入缓存！
                        this.redisTemplate.opsForValue().set(skuKey, skuInfo, RedisConst.SKUKEY_TIMEOUT, TimeUnit.SECONDS);
                        return skuInfo;
                    } finally {
                        //  解锁！
                        lock.unlock();
                    }
                } else {
                    Thread.sleep(1000);
                    return getSkuInfo(skuId);
                }
            } else {
                //  缓存中有数据！
                return skuInfo;
            }
        } catch (InterruptedException e) {
            //  报警----> 程序哥哥： 危险..... 写日志.... sendMSG();
            e.printStackTrace();
        }
        //  返回数据库中的数据！  需要停止redis 容器 ！ docker stop CID
        return getSkuInfoDB(skuId);
    }

    private SkuInfo getSkuInfoByRedis(Long skuId) {
        //判断 获取skuInfo数据
        //获取缓存中的数据  skyKey= sku:+skuId:info;
        String skuKey = RedisConst.SKUKEY_PREFIX + skuId + RedisConst.SKUKEY_SUFFIX;
        try {
            //skuInfo
            SkuInfo skuInfo = (SkuInfo) this.redisTemplate.opsForValue().get(skuKey);
            if (skuInfo == null) {
                //缓存没有数据 skuInfo 废物再利用
                //上锁redis 或者 redssion
                // set key value ex/px timeout nx/xx
                String lockKey = RedisConst.SKUKEY_PREFIX + skuId + RedisConst.SKUKEY_SUFFIX;
                String uuid = UUID.randomUUID().toString();
                Boolean result = this.redisTemplate.opsForValue().setIfAbsent(skuKey, uuid, RedisConst.SKULOCK_EXPIRE_PX1, TimeUnit.SECONDS);
                //如果获取到锁
                if (result) {
                    //获取到锁有权利查询数据库了
                    skuInfo = getSkuInfoDB(skuId);
                    //防止一下缓存穿透  做一个UUID所及穿透就炸了 但现在上面有一道锁炸不了
                    if (skuInfo == null) {
                        SkuInfo skuInfo1 = new SkuInfo();
                        //这个时间不应该太长
                        this.redisTemplate.opsForValue().set(skuKey, skuInfo, RedisConst.SKUKEY_TIMEOUT, TimeUnit.SECONDS);
                        return skuInfo1;
                    }
                    //放入缓存
                    redisTemplate.opsForValue().set(skuKey, skuInfo, RedisConst.SKUKEY_TIMEOUT, TimeUnit.SECONDS);
                    //  释放锁资源！ redis + lua 释放！
                    String script = "if redis.call('get',KEYS[1]) == ARGV[1] then return redis.call('del',KEYS[1]) else return 0 end";

                    //  执行lua 脚本：
                    //  第一个： 表示 RedisScript 需要执行的lua 脚本 第二个： key 第三个： value
                    DefaultRedisScript defaultRedisScript = new DefaultRedisScript();
                    defaultRedisScript.setScriptText(script);
                    defaultRedisScript.setResultType(Long.class);
                    this.redisTemplate.execute(defaultRedisScript, Arrays.asList("lock"), uuid);
                    return skuInfo;

                } else {
                    //自旋：先睡一会再次调用方法
                    Thread.sleep(100);
                    return skuInfo;
                }

            } else {
                //缓存中有数据
                return skuInfo;
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //返回数据库数据
        return getSkuInfoDB(skuId);
    }

    private SkuInfo getSkuInfoDB(Long skuId) {
        SkuInfo skuInfo = skuInfoMapper.selectById(skuId);
        //根据skuId 查询图片列表集合
        QueryWrapper<SkuImage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("sku_id", skuId);
        List<SkuImage> skuImageList = skuImageMapper.selectList(queryWrapper);
        skuInfo.setSkuImageList(skuImageList);
        return skuInfo;
    }

    @Override
    //从数据库中获取实时的价格  需要上锁
    public BigDecimal getSkuPrice(Long skuId) {
        //select price from skuInfo where id = skuid;
        //获取锁
        String lockkey = skuId + ":lock";
        RLock lock = redissonClient.getLock(lockkey);
        //上锁
        lock.lock();
        SkuInfo skuInfo = null;
        BigDecimal price = new BigDecimal(0);
        try {
            QueryWrapper<SkuInfo> skuInfoQueryWrapper = new QueryWrapper<>();
            skuInfoQueryWrapper.select("price").eq("id", skuId);
            skuInfo = skuInfoMapper.selectOne(skuInfoQueryWrapper);
            if (skuInfo != null) {
                price = skuInfo.getPrice();
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            //释放资源
            lock.unlock();
        }
        //默认返回0
        return price;
    }

    @Override
    @GmallCache(prefix = "categoryViewByCategory3Id:")
    public BaseCategoryView getCategoryViewByCategory3Id(Long category3Id) {
        //select * from v_categoryview where id = 61;
        return baseCategoryViewMapper.selectById(category3Id);
    }

    @Override
    @GmallCache(prefix = "SpuSaleAttrList:")
    public List<SpuSaleAttr> getSpuSaleAttrListCheckBySku(Long skuId, Long spuId) {
        return spuSaleAttrMapper.selectSpuSaleAttrListCheckBySku(skuId, spuId);
    }

    @Override
    @GmallCache(prefix = "SkuValueIdsMap:")//分布式锁注解
    public Map getSkuValueIdsMap(Long spuId) {
        Map<Object, Object> hashMap = new HashMap<>();
        // key = 3729|3730 ,value = 21
        List<Map> mapList = skuSaleAttrValueMapper.selectSaleAttrValueBySpu(spuId);

        if (!CollectionUtils.isEmpty(mapList)) {
            mapList.forEach(map -> {
                hashMap.put(map.get("value_ids"), map.get("sku_id"));
            });
        }
        return hashMap;
    }

    @Override
    @GmallCache(prefix = "SpuPosterList:")
    public List<SpuPoster> findSpuPosterBySpuId(Long spuId) {
        QueryWrapper<SpuPoster> spuPosterQueryWrapper = new QueryWrapper<>();
        spuPosterQueryWrapper.eq("spu_Id", spuId);
        return spuPosterMapper.selectList(spuPosterQueryWrapper);
    }

    @Override
    @GmallCache(prefix = "AttrList:")
    public List<BaseAttrInfo> getAttrList(Long skuId) {

        //  获取数据
        List<BaseAttrInfo> baseAttrInfoList = baseAttrInfoMapper.selectAttrList(skuId);

        return baseAttrInfoList;

    }

    @Override
    @GmallCache(prefix = "CategoryList:")
    public List<JSONObject> getCategoryList() {
        //  获取到所有分类数据！
        List<JSONObject> list = new ArrayList<>();
        //  分类名称 + 分类Id 在 base_category_view 视图中！
        List<BaseCategoryView> categoryViewList = baseCategoryViewMapper.selectList(null);
        //  获取一级分类数据 ，以一级分类category1_id 分组，
        //  map key = category1_id value = List<BaseCategoryView>
        //  categoryViewList.stream().map(Collectors.groupingBy(BaseCategoryView::getCategory1Id));
        //  category1_id = 1  category1_id = 2
        Map<Long, List<BaseCategoryView>> listMap =
                categoryViewList.stream().collect(Collectors.groupingBy(BaseCategoryView::getCategory1Id));

        //  声明一个变量index
        int index = 1;
        //  遍历集合
        Iterator<Map.Entry<Long, List<BaseCategoryView>>> iterator = listMap.entrySet().iterator();
        while (iterator.hasNext()) {
            //  创建一个 JSONObject 对象
            JSONObject category1 = new JSONObject();
            Map.Entry<Long, List<BaseCategoryView>> entry = iterator.next();
            Long category1Id = entry.getKey();
            List<BaseCategoryView> categoryViewList1 = entry.getValue();

            //  5个人;
            category1.put("index", index);

            category1.put("categoryName", categoryViewList1.get(0).getCategory1Name());
            category1.put("categoryId", category1Id);

            //  变量自增
            index++;

            //  以二级分类Id 分组
//            categoryViewList.stream().map(Collectors.groupingBy(BaseCategoryView::getCategory2Id));
            Map<Long, List<BaseCategoryView>> listMap2 =
                    categoryViewList1.stream().collect(Collectors.groupingBy(BaseCategoryView::getCategory2Id));
            //  声明一个集合来存储二级分类数据
            List<JSONObject> category2ChildList = new ArrayList<>();
            //  循环遍历
            Iterator<Map.Entry<Long, List<BaseCategoryView>>> iterator1 = listMap2.entrySet().iterator();
            while (iterator1.hasNext()) {
                //  创建一个 JSONObject 对象
                JSONObject category2 = new JSONObject();
                Map.Entry<Long, List<BaseCategoryView>> entry1 = iterator1.next();
                Long category2Id = entry1.getKey();
                List<BaseCategoryView> categoryViewList2 = entry1.getValue();

                category2.put("categoryId", category2Id);
                category2.put("categoryName", categoryViewList2.get(0).getCategory2Name());

                category2ChildList.add(category2);

                //  获取三级分类数据！
//                categoryViewList2.forEach();
                //  声明一个集合来存储三级分类数据
//                List<JSONObject> category3ChildList = new ArrayList<>();
//                for (BaseCategoryView baseCategoryView : categoryViewList2) {
//                    JSONObject category3 = new JSONObject();
//                    category3.put("categoryId", baseCategoryView.getCategory3Id());
//                    category3.put("categoryName", baseCategoryView.getCategory3Name());
//                    category3ChildList.add(category3);
//                }
                //  拉姆达表达式！
                List<JSONObject> category3ChildList = categoryViewList2.stream().map(baseCategoryView -> {
                    JSONObject category3 = new JSONObject();
                    category3.put("categoryId", baseCategoryView.getCategory3Id());
                    category3.put("categoryName", baseCategoryView.getCategory3Name());
                    return category3;
                }).collect(Collectors.toList());

                //  将三级分类数据集合放入二级分类数据
                category2.put("categoryChild", category3ChildList);
            }
            //  将二级分类数据集合放入一级分类数据
            category1.put("categoryChild", category2ChildList);
            //  将一级分类数放入list 集合
            //  ${list}
            list.add(category1);
        }
        //  返回数据！
        return list;
    }

    //   通过tmid 获取品牌信息   之后发布到调用者  productFeignClient
    @Override
    public BaseTrademark getTrademark(Long tmId) {
        return baseTrademarkMapper.selectById(tmId);
    }
}